﻿ 
@model AmazeUI.db.XtUser

@{
    ViewBag.Title = "左侧菜单列表";
}


<div class="am-g">
    <div class="am-u-sm-12">
        <div class="am-panel am-panel-default">
            <div class="am-panel-bd">
                <div class="am-g">
                    <div class="am-u-sm-3">
                        <div class="am-input-group">
                            <span class="am-input-group-label">姓名</span>
                            <input type="text" class="am-form-field" data-bind="value:wdname">
                            <span class="am-input-group-btn">
                                <button class="am-btn am-btn-secondary" onclick="fy(1)" type="button">搜索</button>
                            </span>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
                <tr>
                    <th>@Html.DisplayNameFor(a => a.Id)</th>
                    <th>@Html.DisplayNameFor(a => a.Name)</th>

                    <th>@Html.DisplayNameFor(a => a.LogNum)</th>
                    <th>@Html.DisplayNameFor(a => a.UsingIp)</th>
                    <th>@Html.DisplayNameFor(a => a.XtRole.Name)</th>
                    <th>@Html.DisplayNameFor(a => a.LogTime)</th>
                    <th>操作</th>
                </tr>
            </thead>

            <tbody data-bind="foreach:$root.datalist">
                <tr>

                    <td data-bind="text:Id"></td>
                    <td data-bind="text:Name"></td>

                    <td data-bind="text:LogNum"></td>
                    <td data-bind="text:UsingIp"></td>
                    <td data-bind="text:XtRole2.Name"></td>
                    <td data-bind="text:LogTime"></td>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                                <button data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}" class="am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 角色</button>
                                <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除</button>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>




        <!-- /用户列表 -->
        <!--分页-->
        <ul class="am-pagination am-pagination-default    " data-bind="with:page">
            <li><a href="javascript:void(0);" data-bind="click:function(){$root.gopage(1)}">第一页</a></li>
            <li><a href="javascript:void(0);" data-bind="click:function(){$root.gopage(up)}">上一页</a></li>
            <!--ko foreach: vp-->
            <li data-bind="css:{'active':$data==$parent.page,'disabled':$data==$parent.page}"><a href="javascript:void(0);" data-bind="text:$data,click:function(){$root.gopage($data)}"> </a></li>
            <!--/ko -->
            <li><a href="javascript:void(0);" data-bind="click:function(){$root.gopage(next)}">下一页</a></li>
            <li><a href="javascript:void(0);" data-bind="click:function(){$root.gopage(total)}">最后一页</a></li>
        </ul>
        <!--分页-->
    </div>
</div>

<!--角色-->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">
            更改角色
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            @using (Html.BeginForm())
            {
  
               
            }
        </div>
    </div>
</div>
<!--角色-->
@section scripts{

    <script type="text/javascript" src="/Resource/knockout-3.3.0.js"> </script>
    <script type="text/javascript">


        function Kvm() {
            var k = this;
            //数据集
            k.page = ko.observable();
            k.datalist = ko.observableArray([]);

            k.wdname = ko.observable('');

            k.gopage = function (page) {
                fy(page);
            }
            //修改模型
            k.editmodel = ko.observable({
                Roles: ko.observableArray([])
            });

            //修改方法
            k.edit = function ($model) {

                var m = $.extend(new Object(), $model);
                m.Roles = ko.utils.arrayMap($model.Roles, function (item) {
                    return item.No;
                });

                k.editmodel(m);

                $('#editModal').modal({
                    keyboard: false,
                    remote: true,
                });
            };
            // 提交订单
            k.editsub = function () {
                if ($('#editform').valid()) {
                    var ke = k.editmodel();
                    ke.Roles = ke.Roles.toString();
                    k.editmodel(ke);
                    $.doJsonPost('@Url.Action("Useredit", "Admin")', ko.toJSON(k.editmodel), function (d) {
                        fy(k.datas().page);
                        //按钮变色
                        //$(btn).button('reset');
                        //隐藏修改窗口
                        $('#editModal').modal('hide');
                        //信息提示
                        $alert("操作成功", 0);

                    });
                }
            };
            //删除
            k.del = function ($model) {
                //弹窗
                var cf = confirm("确定该删除");
                if (cf) {
                    $.doAjaxGet('@Url.Action("userDel", "Admin")' + '?id=' + $model.Id, function (d) {
                        if (d.code == 0) {
                            //信息提示
                            $alert("操作成功", 0);
                            k.datalist.remove($model);
                        }
                    });
                }

            };

        }

        var kvm = new Kvm();
        ko.applyBindings(kvm);



        //获取数据
        function fy(page, rows) {
            //行数
            rows = rows || 10;
            $.doPost('@Url.Action("ListData", "User")', { page: page, rows: rows, wdname: kvm.wdname() }, function (d) {
                var opage = $page(page, rows, d.data.count); //绑定
                kvm.page(opage);
                kvm.datalist(d.data.datalist);

            });
        }

        $(function () {
            fy(1);
        });


    
        // 自动完成
        $typeahead("#sousuo", "@Url.Action("Typeahead")"); 

    </script>
}
